package com.yzkj.cpjxc.business.service.impl;

import com.yzkj.cpjxc.business.framework.common.BusinessMap;
import com.yzkj.cpjxc.business.framework.common.Pager;
import com.yzkj.cpjxc.business.framework.utils.IDUtils;
import com.yzkj.cpjxc.business.domain.SysLog;
import com.yzkj.cpjxc.business.domain.SysLogShowVo;
import com.yzkj.cpjxc.business.service.SysLogService;
import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 系统日志事务实现类
 */
@Service
public class SysLogServiceImpl implements SysLogService {

	/**
	 * MyBatis 命名空间
	 */
	private final static String MAPPER_NAMESPACE = "com.chkj.sysMgr.logMgr.sysLog.mappers.SysLogMapper";

	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;

	@Override
	public BusinessMap create(SysLog sysLog) throws Exception {
		BusinessMap bm = new BusinessMap();
		sysLog.setLogId(IDUtils.genUUID());
		sqlSessionTemplate.insert(MAPPER_NAMESPACE + ".add", sysLog);
		return bm;
	}

	@Override
	public Pager<SysLogShowVo> search(Pager<SysLogShowVo> pager, SysLog sysLog) throws Exception {
		List<SysLogShowVo> dataList = sqlSessionTemplate.selectList(MAPPER_NAMESPACE + ".page", sysLog, new RowBounds((pager.getCurrentPage() - 1) * pager.getLimit(), pager.getLimit()));
		pager.setDataList(dataList);

		Long total = sqlSessionTemplate.selectOne(MAPPER_NAMESPACE + ".getTotal", sysLog);
		pager.setTotal(total);
		return pager;
	}

	@Override
	public SysLog getById(String logId) throws Exception {
		return sqlSessionTemplate.selectOne(MAPPER_NAMESPACE + ".getById", logId);
	}

	@Override
	public Pager<SysLogShowVo> search2(Pager<SysLogShowVo> pager, SysLog sysLog) throws Exception {
		List<SysLogShowVo> dataList = sqlSessionTemplate.selectList(MAPPER_NAMESPACE + ".page2", sysLog, new RowBounds((pager.getCurrentPage() - 1) * pager.getLimit(), pager.getLimit()));
		pager.setDataList(dataList);

		Long total = sqlSessionTemplate.selectOne(MAPPER_NAMESPACE + ".getTotal2", sysLog);
		pager.setTotal(total);
		return pager;
	}

}
